package com.cet.lxf.reflection.test04;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-07-29 11:11
 **/
public class Main {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        // 获取构造方法Integer(int)
        Constructor<Integer> constructor = Integer.class.getConstructor(int.class);
        Integer i = constructor.newInstance(123);
        System.out.println(i);

        // 获取构造方法Integer(String):
        Constructor<Integer> constr = Integer.class.getConstructor(String.class);
        Integer j = constr.newInstance("2222");
        System.out.println(j);
    }
}
